package com.turnengine.client.local.location.bean;

import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import java.io.IOException;

/**
 * The Grid Details Serializer.
 */
public class GridDetailsSerializer implements IGridDetailsSerializer {

	@Override
	public IGridDetails readObject(IDataReader reader) throws IOException {

		// Read fields
		int startLocationId = reader.readInt();
		int finishLocationId = reader.readInt();
		int owned = reader.readInt();
		int allied = reader.readInt();
		int hostile = reader.readInt();

		// Create object
		IGridDetails object = new GridDetails();
		object.setStartLocationId(startLocationId);
		object.setFinishLocationId(finishLocationId);
		object.setOwned(owned);
		object.setAllied(allied);
		object.setHostile(hostile);
		return object;
	}

	public void writeObject(IDataWriter writer, IGridDetails object) throws IOException {

		// Get fields
		int startLocationId = object.getStartLocationId();
		int finishLocationId = object.getFinishLocationId();
		int owned = object.getOwned();
		int allied = object.getAllied();
		int hostile = object.getHostile();

		// Write fields
		writer.writeInt(startLocationId);
		writer.writeInt(finishLocationId);
		writer.writeInt(owned);
		writer.writeInt(allied);
		writer.writeInt(hostile);
	}
}
